 
        var g_menuMapOpen = false;
		
 
function closeMenumap() {
    g_menuMapOpen = false;
    $("#menumap").hide('slide',400);
    $("#projects_button").removeClass('clicked');
}

function moveScrollMenumap(direction, included) {
	
	var list_height = $("#menumap_list").height();
    var item_height = $(".menumap_item").height();
    var querylist_height = item_height * included;
    var min_slider_height = 20;
 
    if(querylist_height > list_height) {

		var position = parseInt( $("#menumap_list").css("margin-top") ) + direction;
		
		var upper_limit = (querylist_height-list_height);
		if(position < -upper_limit)
			position = -upper_limit;
		if(position > 0)
			position = 0;
			
		var position_percent =  100 - (-100 * position / upper_limit);
		document.title = included + "," + upper_limit + "," + position + "," + position_percent;
		$("#menumap_scroller").slider('value', position_percent);
		$("#menumap_list").css("margin-top", position);
    }
}

function refreshMenumap(queryText) {
    
    if(queryText != null)
        queryText = queryText.toLowerCase();
 
    var i = 0;
    var included = 1;
    
    jQuery.each($("#menumap_list").children("div").eq(0).children("div"), function() {
                                            
        var includeItem = true;
        var $children = $(this).children();
        
        if(queryText != null) {
            
            includeItem = false;
            var item_titl_str = $children.eq(0).text().toLowerCase();
            var item_terms_str = $children.eq(1).text();
			
            if(item_titl_str.search(queryText) >= 0)
                includeItem = true;
            else if(item_terms_str.search(queryText) >= 0)
                includeItem = true;
        }
    
        if(includeItem) {
            
            var $targetChild = $children.eq(0).show();
            $targetChild.css("position", "relative");
            if(i==0) {
                i = 1;
                $targetChild.addClass("menumap_item alt");
            }
            else {
                i = 0;
                $targetChild.removeClass("menumap_item alt");
            }
            
            included++;
        }
        else {
            $children.eq(0).hide();
        }
    });
    
    var list_height = $("#menumap_list").height();
    var item_height = $(".menumap_item").height();
    var querylist_height = item_height * included;
    var min_slider_height = 20;
 
    if(querylist_height < list_height) {
        
        $("#menumap_scroller").slider('disable');
        $("#menumap_scroller").slider('value', 100);
        $("#menumap_list").css("margin-top", 0);
        $("#menumap_scroller .ui-slider-handle").css("height", min_slider_height);
        $("#menumap_list_container").unbind('mousewheel');
		
		
		$("#menumap_scroller_up").click(function() {});
		$("#menumap_scroller_down").click(function() {});		
	
    }
    else {
        
        var scrollbar_height = list_height / ((item_height * included) - list_height);
 
        $("#menumap_scroller").slider('enable');
        $("#menumap_scroller .ui-slider-handle").css("height", Math.max(min_slider_height, scrollbar_height));
        $("#menumap_scroller").bind('slide', function(event, ui) {
 
            var position = ((100 - ui.value) / 100) * (list_height / scrollbar_height); 
            $("#menumap_list").css("margin-top", -position);
        });
        
        $("#menumap_list_container").bind('mousewheel', function (event, delta) {

            var speed = (list_height / scrollbar_height) * delta * 0.05;
			moveScrollMenumap(speed, included);
        });
		
		
		$("#menumap_scroller_down").click(function() {
 
            var speed = (list_height / scrollbar_height) * 0.05;
			moveScrollMenumap(-speed, included);
		});
		$("#menumap_scroller_up").click(function() {

            var speed = (list_height / scrollbar_height) * 0.05;
			moveScrollMenumap(speed, included);
		});
    }
    
}
 
function initalizeMenumap() {
        
    /*
    Set up the menu map list data
    */
    jQuery.each($("#menumap_list").children("span").eq(0).children("div"), function() {
                                         
        var $children = $(this).children();
		
        var $item_title = $children.eq(0);
        var $item_terms = $children.eq(1);
        var $item_url = $children.eq(2);
        
        $item_terms.text( $item_terms.text().toLowerCase() ).hide();
        $item_url.text( $item_url.text().toLowerCase() ).hide();
         
        var $title_chil = $item_title.children();         
        var $title_titl = $title_chil.filter(".menumap_item.name");
        var $title_desc = $title_chil.filter(".menumap_item.description");
        var $title_logo = $title_chil.filter(".menumap_item.logo");
        
        $title_desc.hide();
        $title_logo.hide();
		$title_logo.css('background', 'url(' + $title_logo.text() + ') center');
		$title_logo.text('');
        
        $item_title.click(function() {
			 
        });
        $item_title.mouseenter(function() {
            $item_title.addClass("highlight");
            $title_titl.css('color', '#ddd');
            $title_desc.fadeIn('fast');
            $title_logo.fadeIn('fast');
        });
        $item_title.mouseleave(function() {
            $item_title.removeClass("highlight");
            $title_titl.css('color', '#333');
            $title_desc.fadeOut('def');
            $title_logo.fadeOut('def');
        });
     
    });
    
    /*
    Set up the menu map search box
    */
    var $search_box = $("#menumap_search");
    $search_box.focus( function() {
        $search_box.val('');
        $("#menumap_search").css({'color' : '#333', 'font-style' : 'normal'});        
        });
    
    $search_box.keydown( function() {
            refreshMenumap($(this).val());
        });
    
    $search_box.keyup( function(event) {
        switch(event.keyCode) {
        
            case 8: case 46: {    /*backspace & delete not caught by keydown?*/
    
                refreshMenumap($(this).val());
            }break;
            
            default: case 27: break;    /*ignore escape*/
        }
    });
 
    $("#menumap_toggle_bar").click(function() {
 
        closeMenumap();
    });
    
    $("#menumap_button_search").click(function() {
 
        refreshMenumap($("#menumap_search").val());
    });
    
    $("#menumap_button_reset").click(function() {
                                              
        $("#menumap_search").val('Enter search terms here');
        $("#menumap_search").css({'color' : '#999', 'font-style' : 'italic'});        
    });
    
    $("#menumap_toggle_button").click(function() {
                                              
        $("#menumap").hide('slide',options,500,callback);    
    });
    
    
        
    /*
    Set up the menu map scroll bar
    */
    $("#menumap_scroller").slider({
        orientation: "vertical",
        range: false,
        min: 0,
        max: 100,
        value: 100
    });
	
	/*
	Nessisary as MSM won't allow files to be referenced in css

    $(".scrollbar .ui-slider-handle").css("background", "url(mysource_files/buttonset_dark.png) no-repeat -252px 50%");
    	*/
    refreshMenumap(null /* for clarity */);
	
	if(g_menuMapOpen == false)
		$("#menumap").hide();
}